home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 8.4 KB | 219 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWArDyna.h
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWARDYNA_H
- #define FWARDYNA_H
-
- #ifndef FWTMAP_H
- #include "FWTMap.h"
- #endif
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- #ifndef FWSTRMRW_H
- #include "FWStrmRW.h"
- #endif
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #include "SLObjReg.xh"
-
- //========================================================================================
- // Typedefs and constants
- //========================================================================================
-
- typedef unsigned long FW_ClassTypeConstant;
- const FW_ClassTypeConstant FW_kPrivByteMask = 0x0FFUL;
-
- //========================================================================================
- // MACROS
- //========================================================================================
-
- #define FW_PRIV_BYTE(a, i) ((FW_ClassTypeConstant(a)&FW_kPrivByteMask)<<(8*i))
- #define FW_TYPE_CONSTANT(a,b,c,d) (FW_PRIV_BYTE(a, 3) + FW_PRIV_BYTE(b, 2) + FW_PRIV_BYTE(c, 1) + FW_PRIV_BYTE(d, 0))
-
- const FW_ClassTypeConstant FW_kNullTypeConstant = FW_TYPE_CONSTANT('n', 'u', 'l', 'l');
- const FW_ClassTypeConstant FW_kWildCardLabel = FW_TYPE_CONSTANT('w', 'i', 'l', 'd');
-
- //----------------------------------------------------------------------------------------
- // FW_REGISTER_ARCHIVABLE_CLASS
- //----------------------------------------------------------------------------------------
-
- #define FW_REGISTER_ARCHIVABLE_CLASS(classLabel, classType, create, initialize, destroy, output) \
- extern void FW_DoNotDeadStrip##classType(); \
- void FW_DoNotDeadStrip##classType() {} \
- FW_CPrivArchiver FWArchive##classLabel(classLabel, \
- FW_CLASSNAME_FROM_TYPE(classType), \
- FW_SPrivArcFun(create, initialize, destroy, output));
-
- //----------------------------------------------------------------------------------------
- // FW_REGISTER_ARCHIVABLE_SOM_CLASS
- //----------------------------------------------------------------------------------------
-
- #define FW_REGISTER_ARCHIVABLE_SOM_CLASS(classLabel, classType, create, initialize, destroy, output) \
- FW_CPrivArchiver FWArchive##classLabel(classLabel, \
- classType##NewClass(0,0)->somGetName(), \
- FW_SPrivArcFun(create, initialize, destroy, output));
-
- //----------------------------------------------------------------------------------------
- // FW_REGISTER_PREV_VERSION_ARCHIVABLE_CLASS
- //----------------------------------------------------------------------------------------
-
- #define FW_REGISTER_PREV_VERSION_ARCHIVABLE_CLASS(oldVersionClassLabel, create, initialize, destroy) \
- FW_CPrivArchiver FWArchive##oldVersionClassLabel(oldVersionClassLabel, \
- FW_SPrivArcFun(create, initialize, destroy, 0));
-
- //----------------------------------------------------------------------------------------
- // FW_DO_NOT_DEAD_STRIP
- //----------------------------------------------------------------------------------------
-
- #define FW_DO_NOT_DEAD_STRIP(classType) \
- extern void FW_DoNotDeadStrip##classType(); \
- FW_DoNotDeadStrip##classType();
-
- //----------------------------------------------------------------------------------------
- // FW_PREREGISTER_RUNTIME_OBJECT
- //----------------------------------------------------------------------------------------
-
- #define FW_PREREGISTER_RUNTIME_OBJECT(stream, object, objectID) \
- FW_CPrivArchiver::PreregisterSpecialObject(stream, object, objectID)
-
- //========================================================================================
- // Forward Declarations
- //========================================================================================
-
- struct FW_SPrivArchiverGlobals;
-
- //========================================================================================
- // Struct FW_SPrivArcStr
- // An internal implementation class used in maps for string-type keys and values
- //========================================================================================
-
- struct FW_SPrivArcStr
- {
- public:
- FW_SPrivArcStr() : fString(NULL) {}
- FW_SPrivArcStr(const char* string);
- const char* fString;
- };
-
- //========================================================================================
- // Struct FW_SPrivArcFun
- // An internal implementation class used in maps for I/O function pointer values
- //========================================================================================
-
- struct FW_SPrivArcFun
- {
- typedef void* (*Create)(FW_CReadableStream& stream, FW_ClassTypeConstant type);
- typedef void (*Initialize)(FW_CReadableStream& stream, FW_ClassTypeConstant type, void* object);
- typedef void (*Destroy)(void* object, FW_ClassTypeConstant type);
- typedef void (*Output)(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
-
- FW_SPrivArcFun() {}
- FW_SPrivArcFun(Create create,
- Initialize initialize,
- Destroy destroy,
- Output output);
- Create fCreateFunction;
- Initialize fInitializeFunction;
- Destroy fDestroyFunction;
- Output fOutputFunction;
- };
-
- //========================================================================================
- // FW_CPrivNameToLabelMap/FW_CPrivLabelToIOFunctionMap
- //========================================================================================
-
- typedef FW_TMap<FW_SPrivArcStr, FW_ClassTypeConstant> FW_CPrivNameToLabelMap;
- typedef FW_TMap<FW_ClassTypeConstant, FW_SPrivArcFun> FW_CPrivLabelToIOFunctionMap;
- typedef FW_TPair<FW_SPrivArcStr, FW_ClassTypeConstant> FW_CPrivNameToLabelPair;
- typedef FW_TPair<FW_ClassTypeConstant, FW_SPrivArcFun> FW_CPrivLabelToIOFunctionPair;
-
- //========================================================================================
- // STRUCT FW_SPrivArchiverGlobals
- //========================================================================================
-
- struct FW_SPrivArchiverGlobals
- {
- FW_CPrivNameToLabelMap* gNameToLabelMap;
- FW_CPrivLabelToIOFunctionMap* gLabelToIOFunctionMap;
- };
-
- //========================================================================================
- // Class FW_CPrivArchiver
- //========================================================================================
-
- class FW_CPrivArchiver
- {
- public:
-
- static void CreateObject(FW_CReadableStream& readableStream, void*& object);
- // Input an object of a dynamic class from the readableStream.
-
- static void OutputObject(FW_CWritableStream& writableStream,
- const void* object,
- const char* className);
- // Output an object of a dynamic class to the writableStream.
-
- static void* PrivCreateObject(FW_CReadableStream& readableStream,
- FW_ClassTypeConstant classLabel);
- // Reads object data for static and dynamic classes from the readableStream.
-
- static void PrivOutputObject(FW_CWritableStream& writableStream,
- FW_ClassTypeConstant classLabel,
- const void* object);
- // Writes object data for static and dynamic classes to the writableStream.
-
- static void PreregisterSpecialObject(FW_CReadableStream& readableStream,
- const void* object,
- FW_ObjectRegistry_ID objectID);
- public:
-
- static void Initialize(FW_SPrivArchiverGlobals& globals);
- static void Terminate();
- static FW_SPrivArchiverGlobals& GetArchiverGlobals();
-
- public:
-
- FW_CPrivArchiver(FW_ClassTypeConstant classLabel,
- const char* className,
- const FW_SPrivArcFun& functions);
- // Register the <classLabel, className, archiving functions> triple with the archiver
-
- FW_CPrivArchiver(FW_ClassTypeConstant classLabel,
- const FW_SPrivArcFun& functions);
- // Register the <classLabel, archiving functions> pair with the archiver
- // This constructor is use for a "previous version" label. The className
- // is therefore unnecessary.
-
- static FW_CPrivLabelToIOFunctionPair* LookupArchivingFunctions(FW_ClassTypeConstant classLabel);
-
- private:
-
- static FW_CPrivNameToLabelMap& GetNameToLabelMap();
- static FW_CPrivLabelToIOFunctionMap& GetLabelToIOFunctionMap();
-
- static void AddNameToLabelPair(FW_ClassTypeConstant classLabel, const char* className);
- static void AddLabelToIOFunctionPair(FW_ClassTypeConstant classLabel, const FW_SPrivArcFun& functions);
-
- private:
- static FW_SPrivArchiverGlobals gGlobals;
-
- private:
- FW_CPrivArchiver(const FW_CPrivArchiver& archiver);
- FW_CPrivArchiver& operator=(const FW_CPrivArchiver& archiver);
- // Shouldn't need to copy this class.
- };
-
- #endif
-